package com.ball.common.utils;

import java.util.Random;

/**
 * 随机生成一个8位数的salt
 */
public class SaltUtils {

    private static final String CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    private static final String NUMBERS = "0123456789";
    private static final int LENGTH = 8;

    public static String getSalt() {
        StringBuilder sb = new StringBuilder(LENGTH);
        Random random = new Random();
        for (int i = 0; i < LENGTH; i++) {
            sb.append(CHARACTERS.charAt(random.nextInt(CHARACTERS.length())));
        }
        return sb.toString();
    }


    public static String getNameSuffix8() {
        StringBuilder sb = new StringBuilder(LENGTH);
        Random random = new Random();
        for (int i = 0; i < LENGTH; i++) {
            sb.append(NUMBERS.charAt(random.nextInt(NUMBERS.length())));
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        SaltUtils generator = new SaltUtils();
        System.out.println("Random Number: " + generator.getNameSuffix8());
    }
}
